#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    while(cin >> n) {
        if(n == 0) break;
        int a = 0, b = 0, cnt = 1, maxcnt = 1, ans = -1;
        for(int i = 0; i < n; i++){
            cin >> b;
            if(ans == -1) ans = b;
            if(a == b){
                if(++cnt > maxcnt){
                    maxcnt = cnt;
                    ans = b;
                }
            }else{
                cnt = 1;
            }
            a = b;
        }
        cout << ans << endl;
    }
}